<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 1、导入mapbox的依赖 js+css -->
    <script src='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css' rel='stylesheet' />
    <style>
        * {
            margin: 0;
            padding: 0
        }

        #map {
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>

<body>
    <!-- 2、设置地图容器的挂载点 -->
    <div id="map">

    </div>
    <script>
        /* 3、实例化地图 */
        mapboxgl.accessToken = 'pk.eyJ1IjoiemhvbmdkaXNodW1hIiwiYSI6ImNsNXJoYXR5eTI2bGgzZW53d2didWF1c3AifQ.6vOplM2NQc_xnJW3aA5ZBA';
        const map = new mapboxgl.Map({
            /* 将地图挂载到对应的DOM上 相当于ol的target */
            container: "map",
            /* 相当于ol的layers */
            style: {
                "version": 8,
                "sources": {
                    "raster-tiles": {
                        "type": "raster",
                        "tiles": ["http://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}"],
                        "tileSize": 256
                    }
                },
                "layers": [{
                    "id": "simple-tiles",
                    "type": "raster",
                    "source": "raster-tiles",
                    "minzoom": 0,
                    "maxzoom": 22
                }]
            },
            center: [113.95073496030112, 22.534723490048986],
            zoom: 14
        })
        /* 定制化背景 */
        map.on("style.load", () => {
            map.setFog({

            })
            let data = 'https://gw.alipayobjects.com/os/basement_prod/972566c5-a2b9-4a7e-8da1-bae9d0eb0117.json'
            map.addLayer({
                id: "shenzhen",
                source: {
                    type: "geojson",
                    data
                },
                type: "fill-extrusion",
                paint: {

                    'fill-extrusion-height': ['get', 'h20'],
                    /* 根据建筑高度不同设置不同颜色 */
                    'fill-extrusion-color': [
                        'interpolate',
                        ['linear'],
                        ['get', 'h20'],
                        //不同高度设置不同颜色
                        0, '#ff2d51',
                        50, '#A67FB5',
                        75, '#C997C7',
                        100, '#DEB8D4',
                        250, '#CA8323'
                    ],
                    'fill-extrusion-opacity': 0.5
                }
            })

        })
    </script>
</body>

</html>